﻿
using Autofac;
using System;
namespace Inovout.Component
{
    public class ComponentRegistry
    {
        private static ComponentResolver defaultComponentResolver;

        public static void Initialize(IContainer container)
        {
            defaultComponentResolver = new ComponentResolver(container);
        }
        private static IComponentResolver applicationComponentResolver;
        public static void SetApplicationComponentResolver(IComponentResolver componentResolverr)
        {
            applicationComponentResolver = componentResolverr;
        }
        public static IComponentResolver ComponentResolver
        {
            get { return applicationComponentResolver ?? defaultComponentResolver; }
        }
        internal static ComponentResolver DefaultComponentResolver { get { return defaultComponentResolver; } }
        public static bool IsRegistered<TService>()
        {
            return ComponentResolver.IsRegistered<TService>();
        }
        public static bool IsRegistered(Type serviceType)
        {
            return ComponentResolver.IsRegistered(serviceType);
        }
        public static object Resolve(Type serviceType)
        {
            return ComponentResolver.Resolve(serviceType);
        }
        public static TService Resolve<TService>(Type serviceType)
        {
            return (TService)Resolve(serviceType);
        }

        public static TService Resolve<TService>()
        {
            return ComponentResolver.Resolve<TService>();
        }


    }
}
